<html>
<head>
    <meta charset="UTF-8">
    <link href="static/assets/global/plugins/bootstrap/css/bootstrap.min.css" rel="stylesheet" type="text/css"/>
    <link href="static/assets/global/css/components.css" rel="stylesheet" type="text/css"/>
    <link href="static/assets/admin/pages/css/login.css" rel="stylesheet" type="text/css"/>
    <script src="static/assets/global/plugins/jquery-1.11.0.min.js" type="text/javascript"></script>
    <title>用户列表</title>
</head>
<body>
    <div class="content">
        <h3 class="form-title">用户列表浏览</h3>
        <div class="table-responsive">
            <table class="table">
                <thead>
                    <tr>
                        <th>用户Id</th>
                        <th>名称</th>
                        <th>性别</th>
                        <th>年龄</th>
                        <th>手机号码</th>
                    </tr>
                </thead>
                <tbody id="container">

                </tbody>
            </table>
        </div>
        <div class="form-actions">
            <button class="btn blue" id="back" type="submit">
                返回
            </button>
        </div>
    </div>

</body>

<script>

    //定义全局订单信息
    var g_userList = [];
    jQuery(document).ready(function () {

        $("#back").on("click",function () {
            window.location.href = "admin.html";
        });

            $.ajax({
                type:"GET",
                url:"http://localhost:8080/user/list",
                //允许跨域请求
                xhrFields:{withCredentials:true},
                success:function (data) {
                    if (data.status=="success") {
                        g_userList = data.data;
                        reloadDom();
                    }else {
                        alert("获取用户信息失败，原因为" + data.data.errMsg);
                    }
                },
                error:function (data) {
                    alert("获取用户信息失败，原因为"+data.responseText);
                }
            });

    });

    function reloadDom() {
        for (var i = 0; i < g_userList.length; i++) {
            var userVO = g_userList[i];
            var genderN = "";
            if (userVO.gender == 0) {
                genderN = "女";
            };
            if (userVO.gender == "1") {
                genderN = "男";
            };
            var dom =
            "<tr>\
			<td>"+userVO.id+"</td>\
			<td>"+userVO.name+"</td>\
			<td>"+genderN+"</td>\
			<td>"+userVO.age+"</td>\
			<td>"+userVO.telephone+"</td>\
			</tr>";
            $("#container").append($(dom));
        }
    }

</script>
</html>